<?php

namespace Drupal\shusy_store_performance\Entity;

use Entity;

class ShusyStorePerformance extends Entity {

  public $id;

  public $vid;

  public $uid;

  public $op_uid;

  public $created;

  public $changed;

  public $is_new_revision;

  public $store_id;

  public $store_order_id;

  public $store_order_line_id;

  public $type;

  public $amount;

  public $description;

  function __construct($values = []) {
    $this->is_new_revision = TRUE;
    parent::__construct($values, 'shusy_store_performance');
  }

  public function save() {
    //0 不记录
    if ($this->amount == 0) {
      return FALSE;
    }

    $this->updated = REQUEST_TIME;
    if (!isset($this->created)) {
      $this->created = REQUEST_TIME;
    }
    $this->op_uid = $GLOBALS['user']->uid;
    if (empty($this->uid)) {
      $this->uid = $GLOBALS['user']->uid;
    }

    shusy_store_performance_change_total($this->store_id, $this->type, $this->amount);

    parent::save();

    return $this;
  }

}
